#ifndef TSB_CONTROLLER_TARGET_SERVER
#define TSB_CONTROLLER_TARGET_SERVER
/*
* 
* @license	Apache License 2.0
* @author	Eugene Kuznetsov
*
*/
#include "Base.hpp"
#include <string>

class CDataBuffer;
class CDoubleBufferQueue;
class CErrorHandler;

class CTargetServer
{
	CTargetServer(std::string ip_address, UInt8 port);
	~CTargetServer();

	Base::eState Init();
	Link::eConnectState Connect();
	Link::eConnectState Disconnect();

	Link::eLinkIOState SendDataToServer(const CDataBuffer* buffer);
	Link::eLinkIOState ReceiveDataFromServer(CDataBuffer& buffer);
	bool IsReadyToReceive(Base::eState& state);

	Link::eConnectState getState() const;
	Int16 getLastError();

public:
	static Base::eState RunTargetServer(std::string ip_address, UInt8 port, CDoubleBufferQueue* buffer_queue, CErrorHandler* error_handler);

private:
	struct HStarterParams
	{
		std::string m_sIpAddress;
		UInt8 m_nPort;
		CDoubleBufferQueue* m_pReceiveSendQueue;
		CErrorHandler* m_pErrorHandler;
	};
	static void TargetServerProcess(void* starter_params);

private:
	Link::eConnectState m_eState;
	bool m_bIsInited;
	std::string m_sIpAddress;
	UInt8 m_nPort;
	Int32 m_nLink;
	/*
	* @todo
	* replace variable m_nLastError with queue of errors
	*/
	Int16 m_nLastError;
};

#endif